<?php 

namespace Admin\Logic;

class LoginLogic{

	private $pre = 'meiyehong';

	public function check($account,$password){
		$password = $this->smcrypt($password);
        $data=array('account'=>$account,'password'=>$password);
		$a = D('Admin');
		$re = $a->where($data)->find();
		 if($re['id']>0){
            $_SESSION['user'] = $re;
            $_SESSION['user']['time'] = time();
        }
        return $re['id'];
	}

	private function smcrypt($password){
        return md5(md5($password).$this->pre);
    }

    public function islogin(){
    	if($_SESSION['user']['id']>0 && $_SESSION['user']['time']>0){
    		return true;
    	}
    	return false;
    }

    public function createUser($data){
        $u = D('Admin');
        $data['password'] = $this->smcrypt($data['password']);
        return $u->add($data);
    }
}





